/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upc.clase.demo.dao.impl;

import edu.upc.clase.demo.dao.ValidarPlanDao;
import edu.upc.clase.demo.entity.ValidarPlan;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;
/**
 *
 * @author RICARDO
 */
public class ValidarPlanDaoImpl extends SimpleJdbcDaoSupport implements ValidarPlanDao {
    private static Logger log = LoggerFactory.getLogger(ValidarPlanDaoImpl.class);
    
    @Autowired
    public ValidarPlanDaoImpl(DataSource dataSource) {
        log.info("Asignando el dataSource");
        setDataSource(dataSource);
    }

    @Override
    public List<ValidarPlan> buscar() {
        return getSimpleJdbcTemplate().query(
                "select `titulo`, `categoria`, `vision_negocio`, `mo_total`, `mo_margen`,'sabio' "
                + " from plan_negocio where estado_plan=?",
                new BeanPropertyRowMapper<ValidarPlan>(ValidarPlan.class));
    }

    @Override
    public ValidarPlan buscar(String titulo) {
         try {
            return getSimpleJdbcTemplate().queryForObject(
                    "select `tiempo`, `mo_roi`, `vision_negocio`, `url_documento`,estado_plan"
                + " from plan_negocio where titulo=?",
                    new BeanPropertyRowMapper<ValidarPlan>(ValidarPlan.class), titulo);
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }
  
    @Override
    public Integer update(ValidarPlan validarplan) {
        int resultado = getJdbcTemplate().update(
                "update plan_negocio set estado_plan=? where titulo=?",
                validarplan.getEstado_plan(), validarplan.getTitulo());   
                
        return resultado;
    }
}
